package com.ruoyi.quartz.task;

import com.ruoyi.bizsys.domain.CreditApply;
import com.ruoyi.bizsys.domain.LoanOrder;
import com.ruoyi.bizsys.service.ICreditFlagService;
import com.ruoyi.bizsys.service.ILoanOrderService;
import com.ruoyi.bizsys.service.ICreditApplyService;
import com.ruoyi.business.service.ICreditService;
import com.ruoyi.business.service.ILoanApplyService;
import com.ruoyi.business.service.ILoanService;
import com.ruoyi.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component("andonTask")
public class AndonTask {

    @Autowired
    ICreditApplyService iCreditApplyService;

    @Autowired
    ILoanOrderService iLoanOrderService;

    @Autowired
    ICreditFlagService iCreditFlagService;

    @Autowired
    ICreditService creditService;

    @Autowired
    ILoanApplyService iLoanApplyService;

    @Autowired
    ILoanService loanService;

    @Autowired
    ISysConfigService iSysConfigService;

    public void returnRun(){
        log.info("进来了：andonTask");
        String andonTaskMinute = iSysConfigService.selectConfigByKey("andon_task_minute");
        againTriggerCredit(Integer.parseInt(andonTaskMinute));
        againTriggerLoan(Integer.parseInt(andonTaskMinute));
    }

    public void againTriggerCredit(Integer andonTaskMinute){
        List<CreditApply> creditApplies = iCreditApplyService.getReturnRunCreditData(andonTaskMinute);

        for (int i = 0;i<creditApplies.size();i++){
            creditService.againTrigger(creditApplies.get(i));
        }
    }

    public void againTriggerLoan(Integer andonTaskMinute){
        List<LoanOrder> loanOrders = iLoanOrderService.getReturnRunLoanData(andonTaskMinute);

        for (int i = 0;i<loanOrders.size();i++){
            loanService.againTrigger(loanOrders.get(i));
        }
    }

}
